#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5;
int a[N], b[N];
LL ans[N];
int n, k;
int cmp(LL a, LL b)
{
	return a > b;
}
int main()
{
	cin >> n >> k;
	LL sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		ans[i] = b[i] - a[i];
		sum += a[i];
	}
	sort(ans + 1, ans + n + 1, cmp);
	for (int i = 1; i <= k; i++) {
		sum += ans[i];
	}
	cout << sum << endl;
	return 0;
}